package me.helllp.book.concurrent.ch03;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 线程池的使用例子
 * 
 * @author Administrator
 *
 */
public class ThreadPoolDemo {
	public static class MyTask implements Runnable{

		@Override
		public void run() {
			System.out.println(System.currentTimeMillis() + " :Thread ID:" + Thread.currentThread().getId());
			try {
				Thread.sleep(1000);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	
	public static void main(String[] args) {
		ExecutorService exec = Executors.newFixedThreadPool(5);
		MyTask task = new MyTask();
		
		for(int i=0; i<10; i++){
			exec.submit(task);
		}
	}
}
